package com.ruoyi.common.constant;

/**
 * 时间单位
 */
public enum TimeUnit {

    SECOND("1", "秒"),
    MIN("2", "分钟"),
    HOUR("3", "小时"),
    DAY("4", "天"),
    WEEK("5", "周"),
    MOON("6", "月"),
    YEAR("7", "年");

    private String code;
    private String unit;

    public static TimeUnit getByCode(String code) {
        for (TimeUnit timeUnit : TimeUnit.values()) {
            if (timeUnit.getCode().equals(code)) {
                return timeUnit;
            }
        }
        return TimeUnit.SECOND;
    }

    public static String getUnitByCode(String code) {
        return getByCode(code).getUnit();
    }

    TimeUnit(String code, String unit) {
        this.code = code;
        this.unit = unit;
    }

    public String getCode() {
        return code;
    }

    public String getUnit() {
        return unit;
    }
}
